<template>
	<div class="port-page">
		<!-- 操作按钮 -->
		<!--<h1 style="width: 100%; text-align: center;">班级课表</h1>-->
		<div style="width: 100%;height: 50px; overflow: hidden;line-height: 50px;">
			<router-link to="/home">
				<el-button type="warning" size="small" style='margin-right: 5px;margin-left: 20px;' icon="el-icon-menu">首页</el-button>
			</router-link>
			<router-link :to="{path:'/home',query: {id:vbjid,frompage:'kb'}}">
				<el-button type="warning" size="small" style=' margin-top:10px;' icon="el-icon-caret-left">返回</el-button>
			</router-link>
			<el-button type="danger" size="small " v-if="showkb" style=" margin-top: 10px;" @click="czkb1()">全部重排</el-button>
			<el-button type="warning" size="small " v-if="showkb" style=" margin-top: 10px;" @click="czkb2()">局部重排</el-button>
		</div>
		<div>
			<ul class="kblistul" v-if="showkb">
				<li style="cursor:pointer;" v-for="i in this.kblistul" @click="daike(i)" :class="(i.issk=='Y'? 'red':'red2')" :style="i.iscf > 0 || i.lsiscf > 0?'background:red;color:#fff':''">
					<p>{{i.sj}}({{i.week}})</p>
					<p>{{i.xh}}</p>
					<p>{{i.jsmc}}</p>
					<p>{{i.zwm}}</p>
					<p>{{i.sjd}}</p>
				</li>
			</ul>
		</div>
		<div v-if="!showkb">
			<h1 style="text-align: center; color: red;margin-top: 10%;">该班级暂无课表，
			<el-button type="text"  v-if="!showkb" style="font-size: 35px; text-decoration:underline" @click="czkb()">马上排课....</el-button>
				</h1>
		</div>
		<el-dialog title="选择Day重排" :visible.sync="centerDialogVisible" width="500px" >
			<el-select clearable v-model="vday"  placeholder="请选择day" @change="getdaysj">
				<el-option :label="v.daymc" :value="v.day" v-for="v in comboxlistday"></el-option>
			</el-select>
			<p style="margin-top: 30px; margin-left: 5px; font-size: 20px;">时间 : {{sj}} &nbsp;{{sjd}}</p>
			<span slot="footer" class="dialog-footer">
			    <el-button @click="centerDialogVisible = false">取 消</el-button>
			    <el-button type="primary" @click="jbcp">确 定</el-button>
			</span>
		</el-dialog>
		<DaikeComponent v-if="classtable" @close="showdaike" :params="this.sjdlist"></DaikeComponent>
		<Czkb @close="cloczkb" :params="this.form" :data="this.xgdata" :day='this.vday' v-if="showczkblist"></Czkb>
	</div>
</template>
<script>
	import qs from 'qs'
	import { mapState } from 'vuex'
	import DaikeComponent from '@/view/educa/banjicourse/edit'
	import Czkb from '@/view/admin/yushebjManage/czkb'
	import moment from 'moment';
	// import './zh-cn'
	export default {
		components: {
			DaikeComponent,
			Czkb
		},
		data() {
			return {
				sj:'',
				sjd:'',
				vday:'',
				centerDialogVisible:false,
				showkb: false,
				xgdata: 1,
				kblistul: [],
				comboxlistday:[],
				classtable: false,
				showczkblist: false,

			}
		},
		created() {
			this.$store.dispatch('changeTitle', this.$route.query.bjmc + '班级课表'); //修改title
			this.$store.dispatch('changeRouterIndex', '/educa/banji'); //修改路由
			if(this.$route.query.iid) {
				this.vbjid = this.$route.query.iid;
			}
			this.getkblist()
			this.loadinfo()
		},

		methods: {
			czkb() {
				this.xgdata = 1
				this.showczkblist = true;
			},
			czkb1() {
				this.vday = ''
				this.$confirm('全部重排将清空原有排课, 是否继续 ? ', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					var logininfo = JSON.parse(localStorage.logininfo);
					var params2 = qs.stringify({
						xxid: logininfo.xxid,
						yhid: logininfo.id,
						bjid: this.$route.query.iid,
						day: '',
					})
					//执行
					this.axios.post(this.$store.state.api + 'bj/delbjkb', params2)
						.then(res => {
							console.log(res, 9999)
							this.xgdata = 1
							this.showczkblist = true;
						}).catch(res => {
							this.$message.warning("服务器异常");
							this.$store.state.loading = false;
						})
				}).catch(() => {
					this.$message({
						type: 'info',
						message: '已取消重排'
					});
				});

			},
			czkb2() {
				this.centerDialogVisible = true
				this.getcomlist2()
//				this.xgdata = 2
//				this.showczkblist = true;
			},
			getcomlist2() {
				var logininfo = JSON.parse(localStorage.logininfo);
				var params2 = qs.stringify({
					yhid: logininfo.id,
					xxid: logininfo.xxid,
					bjid: this.$route.query.iid,
					day:'',
				})
				//执行
				this.axios.post(this.$store.state.api + 'bj/bjdaykb', params2)
					.then(res => {
						console.log(res,999)
						let data = res.data.data;
						let list = data.list;
						this.comboxlistday = list;
						this.vday = this.comboxlistday[0].day
						this.sj = this.comboxlistday[0].sj
						this.sjd = this.comboxlistday[0].sjdid
					}).catch(res => {})
			},
			getdaysj(){
				for(var i in this.comboxlistday){
					if(this.vday == this.comboxlistday[i].day){
						this.sj = this.comboxlistday[i].sj
						this.sjd = this.comboxlistday[i].sjdid
					}
				}
			},
			jbcp(){
				this.$confirm('局部重排将清空已选Day之后课表 , 是否继续 ? ', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					var logininfo = JSON.parse(localStorage.logininfo);
					var params2 = qs.stringify({
						xxid: logininfo.xxid,
						yhid: logininfo.id,
						bjid: this.$route.query.iid,
						day: this.vday,
					})
					//执行
					this.axios.post(this.$store.state.api + 'bj/delbjkb', params2)
						.then(res => {
							console.log(res, 9999)
							this.xgdata = 2
							this.showczkblist = true;
						}).catch(res => {
							this.$message.warning("服务器异常");
							this.$store.state.loading = false;
						})
				}).catch(() => {
					this.$message({
						type: 'info',
						message: '已取消重排'
					});
				});
			},
			cloczkb() {
				this.showczkblist = false;
				//				if(this.params.id) {
				//					this.form.id1 = this.params.id;
				//				} else {
				//					this.form.id1 = this.params.row.id;
				//				}
				this.getkblist()
			},
			daike(list) {
				this.sjdlist = list
				this.classtable = true
			},
			showdaike() {
				this.classtable = false
				//				if(this.params.id) {
				//					this.form.id1 = this.params.id;
				//				} else {
				//					this.form.id1 = this.params.row.id;
				//				}
				this.getkblist()
			},
			getkblist() {
				var logininfo = JSON.parse(localStorage.logininfo);
				var params2 = qs.stringify({
					xxid: logininfo.xxid,
					yhid: logininfo.id,
					bjid: this.$route.query.iid,
					isys: 'N',
				})
				//执行
				this.axios.post(this.$store.state.api + 'ysbj/getbjkb', params2)
					.then(res => {
						this.kblistul = res.data.data.aa
						if(this.kblistul.length > 0) {
							this.showkb = true
						} else {
							this.showkb = false
						}
						console.log(res, 9999)
					}).catch(res => {
						this.$message.warning("服务器异常");
						this.$store.state.loading = false;
					})
			},
			loadinfo() {
				var logininfo = JSON.parse(localStorage.logininfo);
				var params2 = qs.stringify({
					xxid: logininfo.xxid,
					yhid: logininfo.id,
					id: this.$route.query.iid
				})
				//执行
				this.axios.post(this.$store.state.api + 'bj/info', params2)
					.then(res => {
						this.form = res.data.data
					}).catch(res => {
						this.$message.warning("服务器异常");
						this.$store.state.loading = false;
					})
			},

		},
		mounted() {

		},

		computed: {
			...mapState([
				'api' //域名
			]),
			multipleDeleteDisabled() {
				console.log(this.multipleDelNum)
				if(this.multipleDelNum) {
					return false;
				} else {
					return true
				}
			}
		}
	}
</script>

<style lang="less" scoped>
	/*div{color:red}*/
	
	.kblistul {
		width: 97%;
		text-align: center;
		margin: 0 auto;
		margin-top: 15px;
		overflow: hidden;
		li {
			width: 12%;
			height: 150px;
			border: 0.5px solid #ccc;
			float: left;
			margin-left: 5px;
			margin-top: 5px;
			p {
				height: 30px;
				line-height: 30px;
			}
		}
	}
	
	.red {
		background: #C0CCDA;
	}
	
	.red2 {
		background: #fff;
	}
	
	.el-button+.el-button {
		margin-left: 0px;
	}
	
	.port-page {
		position: relative;
		#calendar {
			width: 80%;
			height: 80%;
			margin-top: -33px;
			margin-left: 100px;
		}
		.aa {
			position: absolute;
			top: 55px;
			left: 0px;
		}
		.bb {
			position: absolute;
			top: 10px;
			left: 300px;
		}
	}
	
	.fc-grid .fc-day-number {
		padding: 0 2px;
		position: relative
	}
	
	.fc-grid .fc-day-number span.solarday {
		float: right;
		color: #999
	}
	
	.fc-grid .fc-day-number span.holiday {
		position: absolute;
		left: 40%
	}
</style>